package com.wyzz.hr.exportfile;

import java.io.IOException;
import java.util.List;

import com.wyzz.hr.pojo.Employee;

import jxl.write.*;
import jxl.write.Number;
import jxl.write.biff.RowsExceededException;

public class ExportLeavebalance extends SingleSheetExportHandler {

	public ExportLeavebalance(List result, String sheetTitle) {
		super(result, sheetTitle);
	}

	protected void buildBody() throws RowsExceededException, WriteException,
			IOException {
		int size = result.size();
		for (int i = 0; i < size; i++) {
			Employee emp = (Employee) result.get(i);
			writableSheet.setRowView(i + 1, 500);
			writableSheet.addCell(new Label(0, i + 1, emp.getEmpDistinctNo(),
					defaultCellFormat));
			writableSheet.addCell(new Label(1, i + 1, emp.getEmpName(),
					defaultCellFormat));
			writableSheet.addCell(new Label(2, i + 1, emp.getEmpDeptNo()
					.getDepartmentName(), defaultCellFormat));
			if (emp.getEmpDeptNo1() != null)
				writableSheet.addCell(new Label(3, i + 1, emp.getEmpDeptNo1()
						.getDepartmentName(), defaultCellFormat));
			if (emp.getEmpDeptNo2() != null)
				writableSheet.addCell(new Label(4, i + 1, emp.getEmpDeptNo2()
						.getDepartmentName(), defaultCellFormat));
			if (emp.getEmpDeptNo3() != null)
				writableSheet.addCell(new Label(5, i + 1, emp.getEmpDeptNo3()
						.getDepartmentName(), defaultCellFormat));
			writableSheet.addCell(new Label(6, i + 1, emp.getEmpPbNo()
					.getPbName(), defaultCellFormat));
			if (emp.getLeaveBalance().getLbLeaveType().intValue() == 1)
				writableSheet.addCell(new Label(7, i + 1, "\u5E74\u5047",
						defaultCellFormat));
			else
				writableSheet.addCell(new Label(7, i + 1,
						"\u5E26\u85AA\u75C5\u5047", defaultCellFormat));
			writableSheet.addCell(new Number(8, i + 1, emp.getLeaveBalance()
					.getCanUseTotalDays(), numberCellFormat));
			writableSheet.addCell(new Number(9, i + 1, emp.getLeaveBalance()
					.getUsedTotalDays(), numberCellFormat));
			if (emp.getLeaveBalance().getLbDaysOfYear() != null)
				writableSheet.addCell(new Number(10, i + 1, emp
						.getLeaveBalance().getLbDaysOfYear().floatValue(),
						numberCellFormat));
			if (emp.getLeaveBalance().getLbOtherDays() != null)
				writableSheet.addCell(new Number(11, i + 1, emp
						.getLeaveBalance().getLbOtherDays().floatValue(),
						numberCellFormat));
		}

		writableWorkbook.write();
	}

	protected void buildTitle() throws RowsExceededException, WriteException {
		writableSheet = writableWorkbook.createSheet(sheetTitle, 0);
		writableSheet.setRowView(0, 500);
		writableSheet.setColumnView(0, 15);
		writableSheet.setColumnView(1, 15);
		writableSheet.setColumnView(2, 15);
		writableSheet.setColumnView(3, 15);
		writableSheet.setColumnView(4, 15);
		writableSheet.setColumnView(5, 15);
		writableSheet.setColumnView(6, 15);
		writableSheet.setColumnView(7, 15);
		writableSheet.setColumnView(8, 15);
		writableSheet.setColumnView(9, 15);
		writableSheet.setColumnView(10, 15);
		writableSheet.addCell(new Label(0, 0, "\u5DE5\u53F7", titleCellFormat));
		writableSheet.addCell(new Label(1, 0, "\u59D3\u540D", titleCellFormat));
		writableSheet.addCell(new Label(2, 0, "\u90E8\u95E8", titleCellFormat));
		writableSheet.addCell(new Label(3, 0, "\u4E00\u7EA7\u90E8\u95E8",
				titleCellFormat));
		writableSheet.addCell(new Label(4, 0, "\u4E8C\u7EA7\u90E8\u95E8",
				titleCellFormat));
		writableSheet.addCell(new Label(5, 0, "\u4E09\u7EA7\u90E8\u95E8",
				titleCellFormat));
		writableSheet.addCell(new Label(6, 0, "\u804C\u4F4D", titleCellFormat));
		writableSheet.addCell(new Label(7, 0, "\u4F11\u5047\u79CD\u7C7B",
				titleCellFormat));
		writableSheet.addCell(new Label(8, 0,
				"\u672C\u5E74\u53EF\u7528\u989D\u5EA6\uFF08\u5929\uFF09",
				titleCellFormat));
		writableSheet.addCell(new Label(9, 0,
				"\u672C\u5E74\u5DF2\u7528\u989D\u5EA6\uFF08\u5929\uFF09",
				titleCellFormat));
		writableSheet.addCell(new Label(10, 0,
				"\u672C\u5E74\u989D\u5EA6\uFF08\u5929\uFF09", titleCellFormat));
		if (result != null
				&& !result.isEmpty()
				&& ((Employee) result.get(0)).getLeaveBalance()
						.getLbLeaveType().intValue() == 1) {
			writableSheet.setColumnView(11, 15);
			writableSheet.addCell(new Label(11, 0,
					"\u6CD5\u5B9A\u5E74\u5047\u989D\u5EA6\uFF08\u5929\uFF09",
					titleCellFormat));
		}
	}
}
